//https://leetcode.cn/problems/zi-fu-chuan-de-pai-lie-lcof/
//字符串的排列

class Solution {
public:
    void Process(string& str,string tmp,vector<bool>& vis,set<string>& s)
    {
        if(tmp.size() == str.size())
        {
            s.insert(tmp);
            return ;
        }
        for(int i = 0;i<str.size();i++)
        {
            if(vis[i])
                continue;
            vis[i] = true;
            Process(str,tmp+str[i],vis,s);
            vis[i] = false;
        }
    }
    vector<string> permutation(string s) {
        set<string> unRepeat;
        string tmp;
        vector<bool> visited(256,false); //注意：需要开辟空间！！！否则后序递归vis[i]会越界访问
        Process(s,tmp,visited,unRepeat);
        vector<string> ans(unRepeat.begin(),unRepeat.end());
        return ans;
    }
};